package ThinkInJava;
/**
 * 多态
 * @author Administrator
 *
 */
//基类
class Shape{
	public void draw(){
		System.out.println("shape draw");
	}
	public void erase(){
		System.out.println("shape erase");
	}
	//若子类不覆盖，那么调用父类的方法
	public void printinfo() {
		System.out.println("shape erase");
	}
}
//subclass
class Circle extends Shape{
	@Override
	public void draw(){
		System.out.println("circle draw");
	}
	@Override
	public void erase(){
		System.out.println("circle erase");
	}
}
//subclass
class Rectangle extends Shape{
	@Override
	public void draw(){
		System.out.println("rectangle draw");
	}
	@Override
	public void erase(){
		System.out.println("rectangle erase");
	}
}
class Triangle extends Shape{
	@Override
	public void draw(){
		System.out.println("triangle draw");
	}
	@Override
	public void erase(){
		System.out.println("triangle erase");
	}
}
public class Polymophism {

	public static void main(String[] args) {
  
		System.out.println("kank"+(1+2));
		Shape[] shapes=new Shape[5];
		shapes[0]=new Triangle();
		shapes[1]=new Rectangle();
		shapes[2]=new Circle();
		shapes[3]=new Rectangle();
		shapes[4]=new Triangle();
		for(Shape s:shapes){
			s.draw();
			s.printinfo();
		}
	}
//  output:
//  triangle draw
//	rectangle draw
//	circle draw
//	rectangle draw
//	triangle draw
}
